package net;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class GameServer implements Runnable{
    public ObjectOutputStream oos;
    public ObjectInputStream ois;
	public Socket socket;
	public Thread serverThread;

	public GameServer(Socket server){
		System.out.println("hola");
		try {
			socket = server;
			oos = new ObjectOutputStream(socket.getOutputStream());
			ois = new ObjectInputStream(socket.getInputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
		serverThread = new Thread(this);
		serverThread.start();
	}
	
	public void recieveMessage(Message _msg){
		System.out.println("Cliente: " + _msg);
	}
	
	public void run() {
		while(Thread.currentThread().equals(serverThread)){
			try {
				Message tmp = (Message)ois.readObject();
				System.out.println("tmpServer: " + tmp);
				if(tmp != null){
					recieveMessage(tmp);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		}
	}
}
